from rest_framework import serializers, status
from rest_framework.response import Response

from six_it.models import Question, Reply, Comment, User


class UserSerializers(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id','username','avatar']
class ReplySerializerForSubAndParent(serializers.ModelSerializer):

    user = UserSerializers(read_only=True)

    class Meta:
        model = Reply
        fields = ["id", "content","createtime","useful_count","unuseful_count","user"]

class ReplySerializers(serializers.ModelSerializer):
    user = UserSerializers(read_only=True)
    subs = ReplySerializerForSubAndParent(read_only=True, many=True)
    parent = ReplySerializerForSubAndParent(read_only=True)
    class Meta:
        model = Reply
        fields = ['id','content','createtime','useful_count','problem','unuseful_count'
            ,'subs','user','parent']

class QuestionSerializers(serializers.ModelSerializer):
    # user_id = serializers.StringRelatedField()
    user = serializers.StringRelatedField(read_only=True)

    labels = serializers.StringRelatedField(read_only=True,many=True)

    answer_question = ReplySerializers(many=True,read_only=True)
    # comment_reply = ReplySerializers(many=True,read_only=True)
    comment_question = ReplySerializers(many=True,read_only=True)
    class Meta:
        model = Question
        fields = ['id','content','title','labels','user','createtime','reply',
                  'replyname','replytime','unuseful_count','useful_count'
            ,'visits','answer_question','comment_question',]
